import numpy as np
import pandas as pd
import faker
import matplotlib.pyplot as plt
import plotly.graph_objs as go

# plt.rcParams['figure.figsize'] = (7.0 , 5.0)
# plt.rcParams['font.family'] = ['sans-serf']
# plt.rcParams['font.sans-serif'] = ['SimHei']
# df = pd.read_csv('https://www.gairuo.com/file/data/dataset/GDP-China.csv')
# print(df.head())
# print(df.columns)
# fig = go.Figure()
# fig.add_scatter(y = df['国内生产总值']/df['第一产业增加值'] )
# fig.update_layout(title = {'text' : '产出比' , 'x' : 0.5})
# # fig.show()
# (
#     df.groupby(df.年份>= 2000)
#     .sum()
#     .rename(index = {True : "两千年以后"  , False : "2000年以前"})
# )
#
# df = df.groupby(pd.cut(df.年份,bins = [i for i in range(1952,2018,5)],
#                   right = False)).sum().sort_values( ascending=False)
# print(df)
#
# (
#     df.groupby(pd.cut(df.年份, bins = [i  for i in range(1950,2018 ,5)], right = False))
#     .sum()
#     .sort_values(ascending=False)
# )


# f = faker.Faker('zh-cn')
# df = pd.DataFrame({
#     '客户姓名': [f.name() for i in range(100)],
#     '年龄': [f.random_int(25, 40) for s in range(100)],
#     '最后去电时间': [f.date_between(start_date='-1y', end_date='today')
#                      .strftime('%Y年%m月%d日') for v in range(100)],
#     '意向': [f.random_element(('you', 'wu')) for b in range(100)],
#     '地址': [f.street_address() for m in range(100)]
# })
# print(df)
# df.to_excel('客户资料表.xlsx' , index  = False)


# (
#     pd.DataFrame()
#     .assign(客户姓名=[f.name() for j in range(10)])
#     .assign(年龄=[f.random_int(25, 40) for q in range(10)]
#             .assign(最后去电时间=[f.date_between(start_date='-1y', end_date='today')
#                     .strftime('%Y年%m月%d日') for z in range(10)])
#             .assign(意念=[f.random_element(('you', 'wu')) for l in range(10)])
#             .assign(地址=[f.street_address() for p in range(10)])
#             ))


# plt.rcParams['figure.figsize'] = (10.0, 6.0)
# plt.rcParams['font.family'] = ['sans-serif']
# plt.rcParams['font.sans-serif'] = ['SimHei']
# df = pd.read_csv('https://www.gairuo.com/file/data/dataset/countries-aggregated.csv')
# print(df.tail())
# print(df.columns)
#
# (
#     df.loc[df['Country'] == 'China']
#     .set_index('Date')
#     .Confirmed
#     .plot()
#     .imshow()
# )
# (
#     df.loc[df.Country == 'China']
#     .set_index('Date')
#     .assign(new=lambda x: x.Confirmed.diff())
#     .new
#     .plot()
# )
# (
#     df.loc[df.Date == df.Date.max()]
#     .loc[df.Confirmed > 10000]
#     .assign(rate=lambda x: x.Deaths / x.Confirmed)
#     .sort_value('rate' ,ascending = False)
#     .set_index('Country')
#     .head(10)
#     .rate
#     .sort_values(ascending = True)
#     .plot
#     .barh()
# )
#
# (
#     df.loc[df.Country.isin(['China' , 'US']) , ['Country' , 'Date' , 'Confirmed']]
#     .groupby(['Country' , 'Date'])
#     .max()
#     .unstack()
#     .T
#     .droplevel(0)
#     .plot()
# )
#
# (
#     df.loc[(df.Country.isin(['China' , "US"]) & (df.Date == df.Date.max()))]
#     .assign(rate= df.Date/df.confirmed)
#     .set_index('country')
#     .rate
#     .plot
#     .bar()
# )
import requests

s = requests.Session()
xq = s.get('https://bj.lianjia.com/xiaoqu/1111027382589/')
print(xq.text)
